//
//  UIButton+Extension.swift
//  SinaWeiBo
//
//  Created by 有风 on 16/2/17.
//  Copyright © 2016年 YouFeng. All rights reserved.
//

import UIKit

extension UIButton {
    //
    convenience init(backImageName: String,title: String,textColor: UIColor) {
        self.init()
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        setTitle(title, forState: .Normal)
        setTitleColor(textColor, forState: .Normal)
    }
    
    
    convenience init(backImageName: String?,title: String,textColor: UIColor,imageName: String? = nil,fontSize: CGFloat = 14) {
        self.init()
        if backImageName != nil {
            //按钮的大小会根据北京图片自动修改
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
        }
        if imageName != nil {
            setImage(UIImage(named: imageName!), forState: .Normal)
        }
        
        //设置字体的大小
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitle(title, forState: .Normal)
        setTitleColor(textColor, forState: .Normal)
        //自适应大小
        sizeToFit()
    }

}
